
package com.zsrt.day20170427.ch01;



import java.lang.reflect.Field;

import org.junit.Test;


/**
 * com.zsrt.day20170427.ch01.Student
 * 
 * 属性
 * @author jmj
 * @date 2017年4月27日
 * @time 上午10:32:37
 */
public class FieldTest {

	@Test
	public void test01() throws Exception {
		
		Class clazz = Class.forName("com.zsrt.day20170427.ch01.Student");
		
		//Object obj = clazz.newInstance();
		//Student student = (Student) obj;
		
		//得到公有属性
		Field[] fields = clazz.getFields();
		for(Field f:fields){
			System.out.println(f.getName());
		}
		System.out.println(fields.length);
		
	}
	
	@Test
	public void tets02() throws Exception {
		
		Class clazz = Class.forName("com.zsrt.day20170427.ch01.Student");
		
		//得到所有属性
		Field[] fields = clazz.getDeclaredFields();
		
		System.out.println(fields.length);
	}
	
	/**
	 * 继承父类时 不受父类影响
	 * @throws Exception
	 */
	@Test
	public void test03() throws Exception {
		
		Class clazz = Class.forName("com.zsrt.day20170427.ch01.Student");
		//得到所有属性
		Field[] fields = clazz.getDeclaredFields();
		
		System.out.println(fields.length);
	}
	
	@Test
	public void test04() throws Exception {
		Class clazz = Class.forName("com.zsrt.day20170427.ch01.Student");
		
		Field[] fields = clazz.getDeclaredFields();
	
		for(int index=0;index<fields.length;index++){
			//得到属性的名字
			String name = fields[index].getName();
			
			System.out.println(name);
		}
		
	}
	
	
}
